/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cinemasystem.app.modules.allscheduling_given.Impl;

import com.cinemasystem.app.modules.allscheduling_given.ProvideMovieService;
import com.cinemasystem.model.Movie;
import com.cinemasystem.model.MovieGenre;
import com.cinemasystem.services.crud.MovieGenreCrudService;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author 210226978
 */
public class ProvideMovieServiceImpl implements ProvideMovieService{
    private static ApplicationContext ctx;
    private MovieGenreCrudService movieGenreCrudService;

    @Override
    public Movie getMovie(String movieName, String movieGenre) {
        ctx = new ClassPathXmlApplicationContext("classpath:com/cinemasystem/app/conf/applicationContext-*.xml");
        movieGenreCrudService = (MovieGenreCrudService) ctx.getBean("movieGenreCrudService");
        List<MovieGenre> movieGenreList = movieGenreCrudService.findAll();
        
        for(MovieGenre mg: movieGenreList){
            if(movieGenre.equalsIgnoreCase(mg.getGenre())){
                List<Movie> movies = mg.getMovie();
                for(Movie m: movies){
                    if(movieName.equalsIgnoreCase(m.getMovieName())){
                        return m;
                    }
                }
                
            }
                
        }
        return null;
    }
    
}
